package com.heima.controller;

import com.heima.config.MinioProp;
import com.heima.utils.MinioUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author chenshan
 */
@RestController
@RequestMapping("minio")
public class MinioController {
    @Autowired
    private MinioUtils minioUtils;

    @Autowired
    private MinioProp prop;

    /**
     * 文件上传
     * @param file 文件
     * @return 文件路径  http://192.168.200.130:9000/leadnews/1.png
     * @throws Exception 异常
     */
    @PostMapping
    public String uploadFile(MultipartFile file) throws Exception {
        minioUtils.putObject(prop.getBucket(), file, file.getOriginalFilename(), file.getContentType());

        return prop.getEndpoint() + "/" + prop.getBucket() + "/" + file.getOriginalFilename();
    }
}
